﻿#region License
/*
 *CopyRight (c) By Denuvead All Rights Reserved
 *CreateDate:
 *Info:
 */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PriErp.Tools.Extensions
{
    public static partial class PriErpExtension
    {
        /// <summary>
        /// InvokeRequired Extension
        /// </summary>
        /// <param name="ctl">控件名</param>
        /// <param name="method">执行方法</param>
        static public void UIThread(this Control ctl, MethodInvoker method)
        {
            if (ctl.InvokeRequired)
                ctl.Invoke(method);
            else
                method.Invoke();
        }

        /// <summary>
        /// 从指定控件中移除某控件(同时清理某控件内容)
        /// </summary>
        /// <param name="parent">父控件</param>
        /// <param name="moveCtl">需要移除的控件</param>
        static public void RemoveControl(this Control parent, Control moveCtl)
        {
            if (parent == null) return;
            parent.UIThread(delegate
            {
                if (moveCtl != null)
                {
                    parent.Controls.Remove(moveCtl);
                    moveCtl.Controls.Clear();
                }
            });
        }
    }
}
